package com.xmqian.app.project.ui

import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.viewpager.widget.ViewPager
import com.example.xmqian.R
import com.example.xmqian.databinding.ActivityGuideBinding
import com.xmqian.app.project.common.apiadapter.DisplayCutoutUtils
import com.xmqian.app.project.common.base.BaseMyActivity

/**
 * Desc： 引导界面
 *
 *
 * Author： xmqian
 * Email:xmqian93@163.com
 * Date: 2019/6/10 15:36\
 *
 * @link(com.xmqian.app.project.GuideFragment)
 */
class GuideActivity : BaseMyActivity() {
    var mViewPager: ViewPager? = null

    //引导页图片
    private val GUIDE_IMAGE = intArrayOf(R.drawable.guide1, R.drawable.guide2, R.drawable.guide3)
    private var mAdapter: GuideViewPageAdapter? = null
    private var binding: ActivityGuideBinding? = null

    override fun getLayoutView(): View {
        binding = ActivityGuideBinding.inflate(layoutInflater)
        return binding!!.root
    }

    override fun initView() {
        mViewPager = binding!!.viewPager
        DisplayCutoutUtils.newInstance(this).setDisplayCutouMode(DisplayCutoutUtils.SHORT_EDGES)
        mAdapter = GuideViewPageAdapter(supportFragmentManager)
        mViewPager!!.adapter = mAdapter
        initViewPagerItem()
    }

    override fun initData() {
    }

    private fun initViewPagerItem() {
        mViewPager!!.offscreenPageLimit = GUIDE_IMAGE.size
        mAdapter!!.notifyDataSetChanged()
    }

    private inner class GuideViewPageAdapter @Suppress("deprecation") constructor(fm: FragmentManager) :
        FragmentPagerAdapter(fm) {
        override fun getItem(position: Int): Fragment {
            return GuideFragment.Companion.newInstance(GUIDE_IMAGE, position)
        }

        override fun getCount(): Int {
            return GUIDE_IMAGE.size
        }
    }
}

